package cn.com.zhaoweiping.ie.convert;

import cn.com.zhaoweiping.Constant;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * excel val abstract converter<br>
 *
 * @author 冰羽
 * @version 2.2.0
 */
public abstract class AbstractConstantConverter implements Converter {

  @Override
  public CellDataTypeEnum supportExcelTypeKey() {
    return null;
  }

  @Override
  public Object convertToJavaData(
      CellData cellData,
      ExcelContentProperty contentProperty,
      GlobalConfiguration globalConfiguration)
      throws Exception {
    return CellDataTypeEnum.NUMBER;
  }

  @Override
  public CellData convertToExcelData(
      Object value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration)
      throws Exception {
    if (value instanceof Constant) {
      Constant v = (Constant) value;
      return new CellData(v.getLabel());
    }

    throw new RuntimeException(String.format("不支持的值类型：%s", value.getClass().getName()));
  }
}
